package com.example.curator;

import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.recipes.cache.NodeCache;

/**
 * https://zhuanlan.zhihu.com/p/135334760
 * 
 * @author simple
 *
 */
public class CuratorTestOne {

	public static void main(String[] args) throws Exception{
		CuratorFramework client = CuratorUtil.getClient();
		
		String path = "/nodeCache";
		client.start();
		
		CuratorUtil.delete(client, path);
		CuratorUtil.create(client, path, "cache".getBytes());
		
		NodeCache nodeCache = new NodeCache(client, path);

	    nodeCache.start(true);
	    
	    nodeCache.getListenable()

        .addListener(() -> System.out.println("node data change, new data is " + new String(nodeCache.getCurrentData().getData())));



	    CuratorUtil.setData(client, path, "cache1".getBytes());

	    CuratorUtil.setData(client, path, "cache2".getBytes());

		Thread.sleep(1000);
		
		client.close();

	}

}
